package com.ifonly.ext.shiro.permission;

import com.ifonly.common.StringPool;
import org.apache.shiro.subject.Subject;

/**
 * @author <a href="mailto:ifonlymaster@163.com">ifonly</a>
 * @version 1.0 2015-12-16 16:07
 * @since JDK 1.6
 */
public class HasAnyPermissionsTag extends PermissionTag {
    @Override
    protected boolean showTagBody(String permissionNames) {
        boolean hasAnyPermission = false;

        Subject subject = getSubject();

        if (subject != null) {
            for (String permission : permissionNames.split(StringPool.COMMA)) {

                if (subject.isPermitted(permission.trim())) {
                    hasAnyPermission = true;
                    break;
                }

            }
        }

        return hasAnyPermission;
    }
}
